{% extends "base.html" %}
{% block title %}Formularios{% endblock %}
{% block mainframe %}

			{% if instance %}
				<h1>Instancia: {{ instance.id }}</h1>
				<h2>{{ instance.form.name }}</h2>


				<ul id="s-1" class="section" href="#s-1">
				   <p class="sectionlabel">Metadatos</p>
				   	{% if instance.creation_date %}
					  	<p class="metadata">Fecha de creaci&oacute;n: <span class="metavalue">{{ instance.creation_date }}</span></p>
					  	<p class="metadata">Fecha de modificaci&oacute;n: <span class="metavalue">{{ instance.modification_date }}</span></p>
					{% endif %}
				   	{% if instance.latitude %}
				   		<p class="metadata">Geolocalizaci&oacute;n</p>
					  	<p class="metadataSub">Latitud: <span class="metavalue">{{ instance.latitude }}</span></p>
						<p class="metadataSub">Longitud: <span class="metavalue">{{ instance.longitude }}</span></p>
					{% endif %}
				   	{% if instance.imei %}
					  	<p class="metadata">Imei</strong>: {{ instance.imei }}</p>
					{% endif %}
		 		</ul>

				{% for section in instance.form.section_set.all %}
					 <ul id="s{{ section.id }}" class="section" href="#s{{ section.id }}">
					   <p class="sectionlabel">{{ section.name }}</p>
					   {% for form_field in section.formfield_set.all %}
					   		{% for instance_field in instance_fields %}
						   		{% if instance_field.form_field.id == form_field.id %}

			                       	<li id="f{{ instance_field.id }}" class="{{ form_field.type|lower }}">
										<div class="actions">
											<img src="/beekeeper/images/buttons/more.png" onclick="javascript:expandField('f{{ instance_field.id }}')" class="fieldButton">
										</div>
										{% if instance_field.form_field.type == "IMAGE" %}
											<p> <span class="fieldlabel">{{ form_field.label }}</span>: <span class="fieldvalue"><img src="/beekeeper/media/{{ instance_field.get_text }}" /></span></p>
										{% else %}
											<p> <span class="fieldlabel">{{ form_field.label }}</span> : <span class="fieldvalue">{{ instance_field.get_text }} </span></p>
										{% endif %}
			                       		
			                       		<br />
		
				                       {% if form_field.property_set.all %}
											<div class="properties">
										   {% for property in form_field.property_set.all %}
												<p>{{ property.name }}: {{ property.value }}</p>		                       		
										   {% endfor %}
					                       	</div>
				                       {% endif %}
				                       {% if form_field.fieldoption_set.all %}
											<div class="options">
										   {% for option in form_field.fieldoption_set.all %}
												<p>{{ option.label }}: {{ option.value }}</p>		                       		
										   {% endfor %}
					                       	</div>
				                       {% endif %}

			                       </li>


		                       {% endif %}
	                       {% endfor %}
					   {% endfor %}
					</ul>
				{% endfor %}


				<br/>
			{% else %}
				<h3>No se ha encontrado el instanceulario en la base de datos.</h3>
			{% endif %}

{% endblock %}

{% block sidebar %}
		    <ul>
				<li><a class="item" href="/beekeeper/show_instance_list/{{ instance.form.id }}" id="campo0">
					<img src="/beekeeper/images/tw_back.png" />
					<div class="label">
						<p><strong>Volver atr&aacute;s</strong></p>
					</div>
				</a></li>	
				<li>
				    <form name="elementDelete" class="item" action="/beekeeper/show_instance/{{ instance.id }}/" method="post">
				        {% csrf_token %}
				        <input type="hidden" name="elementToDelete" value="{{ instance.id }}" />
				        <input type="image" src="/beekeeper/images/tw_delete.png" name="submit" />
						<!--<a href="document.elementDelete.submit();"><span class="tableelement"><img class="delete" src="/beekeeper/images/buttons/delete.png" /></span></a>-->
				    </form>
					<!-- <a class="item" href="/beekeeper/delete_instance/{{ instance.id }}" id="campo1"> 
					<img src="/beekeeper/images/delete.png" />
					<div class="label">
						<p><strong>Eliminar instanceulario</strong></p>
					</div>
					</a> -->
				</li>
				<li><a class="item" href="/beekeeper/show_instance_map/{{ instance.id }}" id="campo4">
					<img src="/beekeeper/images/tw_geolocalization.png" />
					<div class="label">
						<p><strong>Geolocalizaci&oacute;n</strong></p>
					</div>
				</a></li>			
			</ul>
{% endblock %}


{% block sectionslinks %}
	<ul>
		<li id="s-1link">
			<a href="#s-1" onclick="selectSection('s-1')">
				Metadatos
			</a>
		</li>
	{% for section in instance.form.section_set.all %}
		<li id="s{{ section.id }}link">
			<a href="#s{{ section.id }}" onclick="selectSection('s{{ section.id }}')">
				Sección {{ section.order }}
			</a>
		</li>
	{% endfor %}
	</ul>
	
{% endblock %}


{% block result %}
	{% if deleting %}
            <p class="enlaceeliminar">¿Desea eliminar la instancia? <br /><a href="/beekeeper/delete_instance/{{ instanceToDelete }}">Sí, eliminar la instancia.</a></p>
    {% endif %}
{% endblock %}


{% block extrajs %}
	{% if deleting %}
		<script language="JavaScript">
			$("#resultado").toggle('slow');
	    </script>
    {% endif %}
{% endblock %}
